package demo06238;

 public class UnsafeTicketSystem {
    private int ticketCount;

    public UnsafeTicketSystem(int ticketCount) {
        this.ticketCount = ticketCount;
    }


    public void sellTicket() {
        if (ticketCount > 0) {
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            ticketCount--;
            System.out.println(Thread.currentThread().getName() + "售出1张票，剩余：" + ticketCount);
        } else {
            System.out.println(Thread.currentThread().getName() + "票已售罄");
        }
    }

    public int getTicketCount() {
        return ticketCount;
    }
}


